package com.example.mydemo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.mydemo.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    //查询所有用户
    @Select("select * from user")
    public List<User> find();

//    插入
    @Insert("insert into user values (#{id},#{name},#{phone},#{sex},#{id_number},#{avator},#{status})")
    public int insert(User user);



    //   查询用户，根据用户id查询信息   select * from user where id =
    @Select("select * from user where id = #{id}")
    User selectById(int id);


    //   查询用户及其所有的订单
    @Select("select * from user")
    @Results(
            {
                    @Result(column = "id",property = "id"),
                    @Result(column = "name",property = "name"),
                    @Result(column = "id",property = "order",javaType = List.class,
                            many=@Many(select = "com.example.mydemo.mapper.OrderMapper.selectByUid")
                    )
            }
    )
    List<User> selectAllUserAndOrder();
}
